<template>
    <div class="phot-component-material">
        <LayoutHeader :title="title" :command="command"></LayoutHeader>
        <div class="content">
            <div class="top">
                <div class="left">
                    <div class="title">材料列表</div>
                    <div class="table-container">
                        <div class="thead">
                            <span class="index">序号</span>
                            <span class="name">材料名称</span>
                            <span class="color">材料呈现颜色</span>
                        </div>
                        <div :class="['td', contentRef.currentIndex === i && 'active']" v-for="(item, i) in deviceManager.materials" :key="i" @click="chooseMaterial(item, i)">
                            <span class="index">{{ i < 9 ? '0' + (i + 1) : (i + 1) }}</span>
                            <span class="name">{{ item.name }}</span>
                            <span class="color">{{ item.color }}</span>
                        </div>
                    </div>
                    <div class="btn-box">
                        <pui-button size="small">编辑</pui-button>
                        <pui-button size="small" type="primary">添加</pui-button>
                        <pui-button size="small" type="danger">删除</pui-button>
                    </div>
                </div>
                <div class="center">
                    <pui-button style="margin-bottom: 10px;" icon="arrow-right" :disabled="true"></pui-button>
                    <pui-button icon="arrow-right" :disabled="true"></pui-button>
                </div>
                <div class="right">
                    <div class="title">材料属性列表</div>
                    <div class="table-container">
                        <div class="thead">
                            <span class="index">序号</span>
                            <span class="length">波长</span>
                            <span class="re">Re(index)</span>
                            <span class="im">Im(index)</span>
                        </div>
                        <div class="td" v-for="(item, i) in contentRef.currentMaterial.properties" :key="i">
                            <span class="index">{{ i < 9 ? '0' + (i + 1) : (i + 1) }}</span>
                            <span class="length">{{ item.waveLength }}</span>
                            <span class="re">{{ item.real }}</span>
                            <span class="im">{{ item.imag }}</span>
                        </div>
                    </div>
                    <div class="btn-box">
                        <pui-button size="small">编辑</pui-button>
                        <pui-button size="small" type="danger">删除</pui-button>
                    </div>
                </div>
            </div>
            <div class="bottom">
                <pui-button>导出材料</pui-button>
                <pui-button>导入材料</pui-button>
                <pui-button type="primary">保存</pui-button>
                <pui-button>取消</pui-button>
            </div>
        </div>
    </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
    name: "Content",
})
</script>
<script lang="ts" setup>
import { reactive } from "vue";
import LayoutHeader from '../LayoutHeader.vue'
import headerData from './index'
import { deviceManager } from "@/services/phot_client/device";
const {title, command} = reactive(headerData.headerRef)
const contentRef = reactive({
    columns: [
        {
            label: "序号",
            field: "id",
            width: "100%",
        },
        {
            label: "材料名称",
            field: "name",
            width: "100%",
        },
        {
            label: "材料呈现颜色",
            field: "color",
            width: "100%",
        },
    ],
    materials: [
        {
            name: "Ag",
            color: "#C0C0C0",
            properties: [
                {id: 1, waveLength: "0.0175", real: 0.8888, imag: 0.0703},
                {id: 2, waveLength: "0.017712", real: 0.8872, imag: 0.071},
                {id: 3, waveLength: "0.017839", real: 0.8855, imag: 0.0717},
                // 可以添加更多属性
            ]

        },
        {
            name: "Al",
            color: "#A9A9A9",
            properties: [
                {id: 1, waveLength: "0.0175", real: 0.8888, imag: 0.0703},
                {id: 2, waveLength: "0.017712", real: 0.8872, imag: 0.071},
                {id: 3, waveLength: "0.017839", real: 0.8855, imag: 0.0717},
            ]
        },
        {
            name: "Au",
            color: "#FFD700",
            properties: [
                {id: 1, waveLength: "0.0175", real: 0.8888, imag: 0.0703},
                {id: 2, waveLength: "0.017712", real: 0.8872, imag: 0.071},
                {id: 3, waveLength: "0.017839", real: 0.8855, imag: 0.0717},
            ]
        },
        // 可添加更多材料
    ],
    currentMaterial: {} as any,
    currentIndex: null as any
})
const chooseMaterial = (item: any, i: any) => {
    contentRef.currentMaterial = item
    contentRef.currentIndex = i
}
</script>

<style lang="scss" scoped>
.phot-component-material {
    box-sizing: border-box;
    font-size: 12px;
    position: flex;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    .content {
        .top {
            margin: 0 auto;
            padding: 15px 20px 0 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;

            .left {
                width: 318px;
                .title {
                    font-size: 12px;
                    margin-bottom: 5px;
                }
                .table-container {
                    border: 1px solid #ddd;
                    border-radius: 4px;
                    height: 309px;
                    overflow-y: auto;

                    .thead {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        height: 50px;
                        background-color: #F5F7FA;
                        position: sticky;
                        top: 0;
                        box-sizing: border-box;
                        border-bottom: 1px solid #ddd;
                    }
                    .td {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        height: 34px;
                        box-sizing: border-box;
                        cursor: pointer;
                        &.active {
                            background-color: #ECF2FE;
                        }
                        &:hover {
                            background-color: #ECF2FE;
                        }
                        span {
                            border: none;
                        }
                    }
                    span {
                        border-right: 1px solid #ddd;
                        font-size: 12px;
                        text-align: left;
                        padding-left: 10px;
                        box-sizing: border-box;
                        flex-shrink: 0;
                        height: 100%;
                        display: flex;
                        justify-content: flex-start;
                        align-items: center;
                        &:last-child {
                            border: none;
                        }
                        &.index {
                            width: 66px;
                        }
                        &.name {
                            width: 108px;
                        }
                        &.color {
                            width: 144px;
                        }
                    }
                }
            }
            .center {
                flex-shrink: 0;
                margin: 0 12px;
                display: flex;
                justify-content: center;
                align-items: center;
                flex-direction: column;
                .pui-btn {
                    margin: 0;
                }
            }
            .right {
                width: 326px;
                .title {
                    font-size: 12px;
                    margin-bottom: 5px;
                }
                .table-container {
                    border: 1px solid #ddd;
                    border-radius: 4px;
                    height: 309px;
                    overflow-y: auto;
                    .thead {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        height: 50px;
                        background-color: #F5F7FA;
                        position: sticky;
                        top: 0;
                        box-sizing: border-box;
                        border-bottom: 1px solid #ddd;
                    }
                    .td {
                        display: flex;
                        justify-content: space-between;
                        align-items: center;
                        height: 34px;
                        box-sizing: border-box;
                        cursor: pointer;
                        &:hover {
                            background-color: #ECF2FE;
                        }
                        span {
                            border: none;
                        }
                    }
                    span {
                        border-right: 1px solid #ddd;
                        font-size: 12px;
                        text-align: left;
                        padding-left: 10px;
                        box-sizing: border-box;
                        flex-shrink: 0;
                        height: 100%;
                        display: flex;
                        justify-content: flex-start;
                        align-items: center;
                        &:last-child {
                            border: none;
                        }
                        &.index {
                            width: 57px;
                        }
                        &.length {
                            flex: 1;
                        }
                        &.re,&.im {
                            width: 87px;
                        }
                    }
                }
            }
            .btn-box {
                margin-top: 10px;
            }
        }
        .bottom {
            position: absolute;
            bottom: 0;
            right: 20px;
            padding: 10px;
            text-align: right;
        }
    }
}

</style>